#pragma once

namespace Json {

class Database;

namespace Schema
{

enum class Type
{
	Null,
	Boolean,
	Int,
	Float,
	String,
	Object,
	Enum,
	Reference,
};

struct FieldInfo
{
	FieldInfo() : basicType(Type::Null), isArray(false) {}
	FieldInfo(Type type) : basicType(type), isArray(false) {}

	Type basicType;
	std::string typeName;
	bool isArray;
};

struct Rename
{
	int revision;
	std::string oldName;
	std::string newName;
};

struct Object
{
	Object() {}

	typedef std::map<std::string, FieldInfo> FieldMap;

	FieldMap fields;

	void RenameField(const std::string& oldName, const std::string& newName, int revision);

	SERIALISATION_DECL_GUID(Json::Schema::Object)

private:
	friend Json::Database;
	std::vector<Rename> m_rename;
};

struct Enum
{
	std::set<std::string> values;

	void RenameValue(const std::string& oldName, const std::string& newName, int revision);

private:
	friend Json::Database;
	std::vector<Rename> m_rename;
};

std::string GetTypeName(const FieldInfo& typeInfo);
bool HasMember(const Object& object, const char* name);
Type GetBasicType(const char* name);

}}